package tk.mynoteapp.dev.demo02.lockscope;

/**
 * 加锁前要清楚锁和被保护的对象是不是一个层面的
 * - 静态字段属于类，类级别的锁才能保护；而非静态字段属于类实例，实例级别的锁就可以保护。
 */
public class Data {
    private static int counter = 0;
    private static Object locked = new Object();

    public static int reset() {
        counter = 0;
        return counter;
    }

    public void wrong() {
        counter++;
    }

    public void right() {
        synchronized (locked) {
            counter++;
        }
    }

    public static int getCounter() {
        return counter;
    }
}
